#ITEM TESTS
import unittest

import game.items.models as i
import game.combat.models as c
import game.damage.models as d
import game.attributes.models as a
import game.actions.models as act

class baseItemCombatTest(unittest.TestCase):
	
	def setUp(self):
		self.size = a.size.objects.create(name='Normal')
		self.dmc1 = d.damageModifierCollection.objects.create(
		basePhysicalDefence=1, baseMagicalDefence = 0)
		self.dtp= d.damageType.objects.create(name='PhysicalDamage',
					physical=1)
		self.dtx = d.damageType.objects.create(name='Unblockable', physical=0)
		self.dm1= d.damageModifier.objects.create(damageType = self.dtp,
					power=3, damageModifierCollection = self.dmc1)
		self.material=i.material.objects.create(name='Test Material', 
					damageModifierCollection = self.dmc1)
		self.dmc2 = d.damageModifierCollection.objects.create(
					basePhysicalDefence=1, baseMagicalDefence = 0)
		self.dmc3 = d.damageModifierCollection.objects.create(
					basePhysicalAttack = 1)
		self.dm2= d.damageModifier.objects.create(damageType = self.dtp,
					power=3, damageModifierCollection = self.dmc2)
		self.dm3= d.damageModifier.objects.create(damageType = self.dtp,
					power=1, damageModifierCollection = self.dmc3, defence=0)
		
	def tearDown(self):
		d.damageType.delete(self.dtp)
		d.damageType.delete(self.dtx)
		d.damageModifier.delete(self.dm1)
		d.damageModifier.delete(self.dm2)
		d.damageModifierCollection.delete(self.dmc1)
		d.damageModifierCollection.delete(self.dmc2)
		a.size.delete(self.size)

class ArmorTest(baseItemCombatTest):
	def testDefence(self):
		""" armor and material return proper defence """
		self.itype= i.itemType.objects.create(name='test')
		self.armor= i.armor.objects.create(name='Test Armor', 
					itemType=self.itype,
					damageModifierCollection=self.dmc2)
		self.assertEquals(self.armor.getDefence(self.dtp), 3)
		self.assertEquals(self.armor.getDefence(self.dtx), 0)
		self.assertEquals(i.item.objects.all()[0].getDefence(self.dtx), 0)  #Test polymorphic behavior, get armor from item

class WeaponTest(baseItemCombatTest):
	def testAttack(self):
		""" Weapon generates damage modified by material"""
		self.attack= act.attack.objects.create(name='test attack',
				damageType=self.dtp, diceNum=1, diceSize=10, power=1)
		self.weapon= i.weapon.objects.create(name='Test Weapon',
				attack = self.attack)
		self.assert_(self.weapon.damage.amount in range(1,11))
		self.assertEquals(self.weapon.damage.power , 1)
